0 GRAPHICS 0:POKE 752,1
Set up screen, hide cursor.
DIM P(1),F(1),F$(15),AX(5),AS(5),S(1),H(1),SC(1)
DIMension space for variables. Array P is the X position for both players.
Array F is the countdown to the next time each player can Fire again.
F$ is for Player graphics data.
Array AX is the X position of the 4 vehicles that can be in the sky.
Array AS is the speed of the 4 vehicles that can be in the sky.
Array S is the number of shots each player has taken.
Array H is the number of successful vehicle hits each player has made.
Array SC is the score for both players.
F=ADR(F$):P(0)=90:P(1)=90:AS(0)=5:AS(1)=6:AS(4)=3
Get the memory location of F$ for stuffing graphics into the Players later. 
Set staring location (P) for both players.
Set starting speed for three of the enemy vehicles.
1 AS(5)=5
and the fourth enemy vehicle.
F$={mess of ATASCII}
This contains the Player graphics for the two players and the spaceship vehicle.
A=PEEK(106)-32:POKE 54279,A:PM=256*A:POKE 559,46:POKE 53277,3:POKE 623,1:POKE 704,60:POKE 705,100:POKE 706,120:POKE 707,200:POKE 710,0
2 POKE 53248,100:POKE 53256,1:POKE 53257,1:POKE 704,55:POKE 53248,155
Impenetrable mess that sets up Player/Missiles and sets colors. I wanted to do a game that uses all four players and all four missiles. That means a lot of POKEs.
FOR I=0 TO 4*128:DPOKE PM+I*2,0:NEXT I
Clear out Player/Missile memory.
MOVE F,PM+529,5:MOVE F+5,PM+746,5:MOVE F+10,PM+820,5
Install the graphics for Player 0 which is played by player 1, the player 2 Player which is played by Player 1, and enemy spaceship in Player 2
3 MOVE F+10,PM+960,5
and the other spaceship in Player 3 (which uses the same graphic as the first one.)
COLOR 46:FOR I=404 TO 490 STEP 2:DPOKE PM+I,15:PLOT RAND(40),RAND(23):NEXT I
Missiles 0 and 1 are the lasers that correspond with Players 0 and 1. Write the graphics for those to memory. Since its just a long dotted line, do it with fornext instead of F$. Also use that loop to draw background stars.
DPOKE PM+445,53184:DPOKE PM+443,16176
Missiles 2 and 3 are the little hard-to-hit satellites. These two DPOKES poke their tiny graphics into Missile memory without disturbing the lasers in Missiles 0 and 1.
POKE 53260,0
Normal-width missiles.
WHILE T<100
Now the main game loop. This will go until 100 vehicles drive by. It really ends up being 96 or so, but whatever.
SOUND :POKE 53278,1
Blissful quiet. Clear the Player/Missile hit register.
FOR X=0 TO 1
For each player
4   P(X)=P(X)+5*((STICK(X)=7)-(STICK(X)=11)):IF P(X)<48:P(X)=48:ENDIF :IF P(X)>191:P(X)=191:ENDIF:POKE 53248+X,P(X)
Let them move their shooty base thing move left or right, but not too far left or right.
IF STRIG(X)=0 AND F(X)<1
If player X is pressing the fire button, and the fire countdown timer allows it (is less than 0)
POKE 53252+X,P(X)+8
Show that players laser beam.
F(X)=4:S(X)=S(X)+1:
Set shot timer. This is so you cant shoot constantly. Increment number of shots made for stats.
FOR W=4 TO 5
The Atari hardware registers Player collisions with other Players, and Player collisions with Missiles, but doesnt detect hot Missile-on-Missile action. Since the lasers are missiles and the little satellite enemies are also missiles, we need to detect hits in low-tech way, by comparing their X positions. So, for each of the satellites
5     IF P(X)=AX(W)-8 OR P(X)=AX(W)-9
We know hes shooting right now, so if the players laser is lined up with either side of the the two-pixel satellite
H(X)=H(X)+1:SC(X)=SC(X)+250*ABS(AS(4)):SOUND 3,20,8,8:AX(W)=25
Increase Hits by one and score (depending on satellite speed.) Play a little boom. Move the satellite offscreen so that it will get a new speed and direction later.
ENDIF :NEXT W
Finish up satellite hit checking.
ELSE :POKE 53252+X,0:F(X)=F(X)-1
Player isnt shooting right now, so make sure the laser is offscreen and decrement the firing counter.
IF F(X)>1:SOUND X,65-3*F(X),10,10:ELSE 
If the firing counter isnt 0, play a sound. It changes as the counter decrements. I am not thrilled with how this sound comes out.
6     SOUND X,0,0,0:ENDIF :ENDIF
Otherwise blissful silence.
IF PEEK(53256+X)&4
Now we get to use the hardware register to see if the laser hit either flying saucer. If player hit one of them
H(X)=H(X)+1:SC(X)=SC(X)+50*ABS(AS(0)):SOUND 2,90,8,8:AX(0)=25:ENDIF
Increment Hits, increase score (saucers are worth less than satellites), play a sound. Move the saucer offscreen for now.
IF PEEK(53256+X)&8:H(X)=H(X)+1:SC(X)=SC(X)+50*ABS(AS(1))
7    SOUND 3,110,8,8:AX(1)=25:ENDIF:NEXT X
Same check and effects for the other saucer.
FOR X=0 TO 5
Now well check to see if any of the 4 enemies are are the edge of the screen, either because theyve been shot or they just flew there on their own.
IF AS(X)
There are only four enemies, 0, 1, 4, and 5. (2 and 3 are the lasers.) So ignore things with Speed of 0. Lasers always have speed 0.
AX(X)=AX(X)+AS(X):POKE 53250+X,AX(X)
Move the enemy horizontally.
IF AX(X)<45 OR AX(X)>195 AS(X)=RAND(10)+6:IF RAND(2):AX(X)=40:ELSE :AX(X)=200:AS(X)=-AS(X):ENDIF 
If its too far off either side of the screen, give it a random new speed and side of the screen. Negative speed if its on the right side of the screen moves it left.
8     T=T+1:ENDIF :ENDIF :NEXT X
Somethings edged of the screen, so the timer ticks away.
POSITION 0,0:PRINT $;SC(0):POSITION 0,22:PRINT $;SC(1):POSITION 29,0:PRINT Timer ;100-T; :WEND
Update on-screen scores and timer info. Thats the end of the main loop.
POKE 53277,0:GRAPHICS 0:SOUND
Games over, so turn off P/M graphics and sound. 
FOR X=0 TO 1:PRINT PLAYER ;X+1:PRINT SCORE $;SC(X):PRINT SHOTS ;S(X)
9  PRINT HITS ;H(X):IF S(X):PRINT ACCURACY ;(H(X)/S(X))*100;%:ENDIF :NEXT X
Print scores and stats.
PAUSE 99:PRINT TRIGGER TO PLAY AGAIN:WHILE STRIG(0):WEND :CLR :RUN 
Wait to play again.
Stay alive, fly 55.

